home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C/C++ Users Group Library 1996 July
/
C-C++ Users Group Library July 1996.iso
/
vol_100
/
168_01
/
sdb.mem
< prev
next >
Wrap
Text File
|
1985-08-19
|
25KB
|
1,007 lines
SDB - a Simple Database System
by David Betz
114 Davenport Ave.
Manchester, NH 03103
(603) 625-4691
Converted to the IBM/PC by
David N. Smith
44 Ole Musket Lane
Danbury, CT 06810
(203) 748-5934
1.0 INTRODUCTION
SDB is a simple database manager for small systems. It was
developed to provide a relatively low overhead system for
storing data on machines with limited disk and memory
resources. The current version runs on a PDT-11/150 with 2
RX01 floppy disk drives and 60K bytes of memory under the
RT-11 operating system. (it also runs on the VAX under VMS)
SDB was originally intended to be a relational database
system, so many of the terms used in describing it are taken
from the relational database literature. Within the context
of SDB the user can safely make the following associations:
1. RELATION can be taken to mean FILE
2. TUPLE can be taken to mean RECORD
3. ATTRIBUTE can be taken to mean FIELD
It should be noted that SDB is not a relationally complete
system. It provides the relational operations of SELECT,
PROJECT, and JOIN, but does not provide the set operations
of UNION, INTERSECTION, or DIFFERENCE as well as some
others.
2.0 RELATION FILE FORMATS
SDB maintains a separate file for each relation that the
user creates. This file contains a header block containing
the definition of the relation including the names and types
of all of the relation's attributes. The remainder of the
file contains fixed length records each containing one tuple
from the relation.
Tuples can be of three types:
1. active - tuples that contain actual active data
2. deleted - tuples that have been deleted
3. unused - tuples that haven't been used yet
SDB - a Simple Database System Page 2
Initially, all tuples are unused. When a new tuple is
stored into a relation, the first unused tuple is found
(they are all contiguous at the end of the relation file).
The new tuple is stored as an active tuple.
When a tuple is deleted, it is marked as such. The space
previously allocated to the deleted tuple is left unused
until the relation is compressed.
It is possible that when attempting to store a new tuple, no
unused tuple can be found even though the relation contains
fewer than the maximum active tuples. This happens when
tuples have been deleted since the time the relation file
was last compressed.
The compress function allows all of the space lost by
deleting tuples to be regained. It does this by copying all
of the active tuples as far backward in the file as possible
leaving all of the available space toward the end of the
file.
3.0 SELECTION EXPRESSIONS
A selection expression specifies a set of tuples over which
some SDB operation is to be executed. The syntax for a
selection expression is:
<rse> ::= <rnames> [ where <boolean> ]
<rnames> ::= <rname> [ , <rname> ] ...
<rname> ::= <relation-name> [ <alias> ]
When a single relation name is specified in a selection
expression, each tuple within that relation becomes a
candidate for selection.
When more than one relation name is specified, the tuples
are formed by taking the cross product of all specified
relations. If a relation is to be crossed with itself, an
alias must be given to one or both of the occurances of that
relation name in the selection expression. This allows SDB
to determine which relation occurance is being refered to in
the boolean part of the selection expression.
After the set of candidate tuples is determined, the boolean
expression is evaluated for each candidate. The candidates
for which the boolean expression evaluates to TRUE become
the selected tuples.
SDB - a Simple Database System Page 3
4.0 INITIALIZATION FILE AND COMMAND FILES
When SDB is first run, it attempts to read and process
commands from a file named "SDB.INI". This file usually
contains macro definitions, but can contain any valid SDB
command. In addition, it is possible to process command
files from within SDB. This is done by typing an '@'
followed by the command file name after the SDB prompt.
5.0 FILE NAMES
Whenever a file name is allowed in the syntax for a command,
it is possible to use either an identifier or a quoted
string. An identifier is interpreted as the file name and a
string is interpreted as a full file specification. The
string form allows for the specification of an alternate
device or extension.
6.0 FORM DEFINITION FILES
A form definition file contains a template into which
attribute values are substituted during a print operation.
There are two types of information that can be included in a
form definition:
1. Literal text
2. Attribute references
Attribute references are indicated by placing the name of
the attribute being referenced between a pair of angle
brackets. Literal text is anything that is not enclosed in
angle brackets.
SDB - a Simple Database System Page 4
Example:
________
print using test amount,category from checks;
Where test.frm contains:
Amount: <amount>
Category: <category>
7.0 ALIASES FOR RELATIONS AND ATTRIBUTES
When a relation or attribute name is specified in a print
statement, it is possible to provide an alternate name for
that relation or attribute. This is useful for relations,
when it is necessary to join a relation to itself. It is
useful for attributes when it is desired that the column
headers in a table be different from the actual attribute
names. Also, alternate attribute names can be used in
references to that attribute in the where clause as well as
in a form definition file. The syntax for specifying
aliases is:
<name> <alias>
Example:
________
print using test amount a,category c from checks;
Where test.frm contains:
Amount: <a>
Category: <c>
SDB - a Simple Database System Page 5
8.0 BOOLEAN EXPRESSIONS
The syntax for boolean expressions:
<expr> ::= <land> [ '|' <land> ]
<land> ::= <relat> [ '&' <relat> ]
<relat> ::= <primary> [ <relop> <primary> ]
<primary> ::= <term> [ <addop> <term> ]
<term> ::= <unary> [ <mulop> <unary> ]
<unary> ::= <factor> | <unop> <unary>
<factor> ::= <operand> | '(' <expr> ')'
<operand> ::= <number> | <string> | <attribute>
<attribute> ::= [ <rname> . ] <aname>
<relop> ::= '=